// Copyright (c) 2007 Robin Boerdijk. All rights reserved.
//
// This software is licensed under the terms of the Microsoft Reciprocal License as described 
// in the file LICENSE.txt, which you should have received as part of this distribution. The 
// license terms are also available at http://www.opensource.org/licenses/ms-rl.html.

#include "wtkpc.h"

#include "wtk/Clipboard.h"

namespace wtk
{
	Clipboard::Clipboard(Window *window)
	{
		if (window == NULL) {
			win32::OpenClipboard(NULL);
		} else {
			window->OpenClipboard();
		}
	}

	Clipboard::~Clipboard()
	{
		win32::CloseClipboard();
	}

	bool Clipboard::GetText(std::wstring &text)
	{
		if (!win32::IsClipboardFormatAvailable(CF_UNICODETEXT)) {
			return false;
		}
		HGLOBAL handle = win32::GetClipboardData(CF_UNICODETEXT);
		if (handle == NULL) {
			return false;
		}
		text = static_cast<wchar_t *>(win32::GlobalLock(handle));
		win32::GlobalUnlock(handle);
		return true;
	}
}
